package howl.types;

import java.io.*;

public class Serializer {

	public static byte[] put(Object o) throws IOException {

		ByteArrayOutputStream b = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(b);
		oos.writeObject(o);
		oos.close();
		return b.toByteArray();
	}

	/**
	 * Retrieves the Object from the object store, Type is preserved although a
	 * cast is necessary
	 * 
	 * @throws ClassNotFoundException
	 * @throws IOException
	 */
	public static Object get(byte[] ob) throws IOException,
			ClassNotFoundException {

		ByteArrayInputStream b = new ByteArrayInputStream(ob);
		ObjectInputStream ois = new ObjectInputStream(b);
		Object o = ois.readObject();
		ois.close();
		return o;

	}

}